package com.binary.coder.gift.core.interfaces.bill.facade;


import com.binary.coder.gift.core.application.bill.AccountApplication;
import com.binary.coder.gift.core.common.bean.PageBean;
import com.binary.coder.gift.core.common.bean.ResultBean;
import com.binary.coder.gift.core.interfaces.bill.assembler.AccountAssembler;
import com.binary.coder.gift.core.interfaces.bill.dto.req.PageQueryAccountBookReq;
import com.binary.coder.gift.core.interfaces.bill.dto.req.PageQueryAccountRecordReq;
import com.binary.coder.gift.core.interfaces.bill.dto.req.SaveAccountBookReq;
import com.binary.coder.gift.core.interfaces.bill.dto.req.SaveAccountRecordReq;
import com.binary.coder.gift.core.interfaces.bill.dto.res.PageQueryAccountBookRes;
import com.binary.coder.gift.core.interfaces.bill.dto.res.PageQueryAccountRecordRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author weitao
 */
@Api(tags = "记账相关接口")
@RestController
@RequestMapping("/api/account")
public class AccountController {

    @Resource
    private AccountApplication accountApplication;


    @ApiOperation("账本-保存")
    @PostMapping("book/save")
    public ResultBean saveAccountBook(@RequestBody SaveAccountBookReq req) {
        accountApplication.saveAccountBook(AccountAssembler.getAccountBookEntity(req));
        return ResultBean.success();
    }

    @ApiOperation("账本-分页查询")
    @GetMapping("book/query/page")
    public ResultBean<PageBean<PageQueryAccountBookRes>> pageQueryAccountBook(PageQueryAccountBookReq req) {
        return ResultBean.success(accountApplication.pageQueryAccountBook(req));
    }



    @ApiOperation("记账-保存")
    @PostMapping("record/save")
    public ResultBean saveAccountRecord(@RequestBody SaveAccountRecordReq req) {
        accountApplication.saveAccountRecord(AccountAssembler.getAccountRecordEntity(req));
        return ResultBean.success();
    }

    @ApiOperation("记账-分页查询")
    @GetMapping("record/query/page")
    public ResultBean<PageBean<PageQueryAccountRecordRes>> pageQueryAccountRecord(@RequestBody PageQueryAccountRecordReq req) {
        return ResultBean.success(accountApplication.pageQueryAccountRecord(req));
    }



}
